﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using QxFramework.Core;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class EscList : UIBase
{
    GameObject Back;
    GameObject Load;
    GameObject Home;
    GameObject Exit;
    // Start is called before the first frame update
    private void Awake()
    {
        Back = transform.Find("Back").gameObject;
        Load = transform.Find("Load").gameObject;
        Home = transform.Find("Home").gameObject;
        Exit = transform.Find("Exit").gameObject;
        AudioControl.Instance.PlaySound("Button");
        var buttons = transform.GetComponentsInChildren<Button>();
       /* foreach(var x in buttons)
        {
            x.onClick.SetListener(() => { Debug.Log("Button"); AudioControl.Instance.PlaySound("Button"); });
        }
        */
        Back.GetComponentInChildren<Button>().onClick.SetListener(() =>
        {
            UIManager.Instance.Close("EscList");
        });


        Home.GetComponentInChildren<Button>().onClick.SetListener(() =>
        {
            UIManager.Instance.Open("DialogWindowUI", 5, args: new DialogWindowUI.DialogWindowUIArg
      ("注意", "确定要回到主界面吗?\n没有保存的内容都会丢失", null, "确定", "取消", () => {
          ProcedureManager.Instance.ChangeTo<TitleProcedure>();
          //   MessageManager.Instance.Get<GameControl.GameAction>().DispatchMessage(GameControl.GameAction.ReturnToHome, this, null);
      }));

        });



        Exit.GetComponentInChildren<Button>().onClick.SetListener(() =>
        {
            UIManager.Instance.Open("DialogWindowUI", 5, args: new DialogWindowUI.DialogWindowUIArg
      ("注意", "确定要退出游戏吗?\n没有保存的内容都会丢失", null, "确定", "取消", () => 
      {
           #if UNITY_EDITOR
                 UnityEditor.EditorApplication.isPlaying = false;
           #else
                    Application.Quit();
           #endif
      }
      ));

        });



        Load.GetComponentInChildren<Button>().onClick.SetListener(() =>
        {
            UIManager.Instance.Open("DialogWindowUI", 5, args: new DialogWindowUI.DialogWindowUIArg
      ("注意", "确定要返回上一个存档点吗?\n没有保存的内容都会丢失", null, "确定", "取消", () => {
          if(LevelManager.Instance.CurrentLevel!="End")
          ProcedureManager.Instance.ChangeTo<SceneLoadProcedure>(new SceneLoadPair(LevelManager.Instance.CurrentLevel, typeof(GameProcedure)));
          else ProcedureManager.Instance.ChangeTo<SceneLoadProcedure>(new SceneLoadPair("Map1.0", typeof(GameProcedure)));
      }));

        });
    }
}
